/*
 *Copyright (c) 2024 Black Sesame Technologies
 *
 *Licensed under the Apache License, Version 2.0 (the "License");
 *you may not use this file except in compliance with the License.
 *You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *Unless required by applicable law or agreed to in writing, software
 *distributed under the License is distributed on an "AS IS" BASIS,
 *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *See the License for the specific language governing permissions and
 *limitations under the License.
*/

#ifndef __HSCG_FIRMWARE_CODE_STATISTIC_H__
#define __HSCG_FIRMWARE_CODE_STATISTIC_H__
#include "types.h"

/**************************** Statistics code timestamp information related function START *****************************/
#ifdef STATISTICS_CODE_TIMESTAMP_ENABLE

#define STATISTICS_CODE_TIMESTAMP_GRPNUM 1
#define TIMESTAMP_CODE_NUM 16

enum statistics_code_timestamp_step {
    TIMESTAMP_CODE_WDG_KICK_START = 0,
    TIMESTAMP_CODE_WDG_KICK_END,
    TIMESTAMP_CODE_CAN_INPUT_START,
    TIMESTAMP_CODE_CAN_IPC_START,
    TIMESTAMP_CODE_ETH2CAN_START,
    TIMESTAMP_CODE_CAN_OUTPUT_START,
    TIMESTAMP_CODE_CAN_OUTPUT_END,
};

struct statistics_code_timestamp_t {
    uint64 timestamp[TIMESTAMP_CODE_NUM];
    uint64 min_delay[TIMESTAMP_CODE_NUM];
    uint64 max_delay[TIMESTAMP_CODE_NUM];
};

extern struct statistics_code_timestamp_t *statistics_code_timestamp;

#define STATISTICS_UPDATE_CODE_TIMESTAMP(step_inx) statistics_code_timestamps_update(step_inx)

#define STATISTICS_UPDATE_CODE_LOOP() statistics_code_loop_inc()
#else
#define STATISTICS_UPDATE_CODE_TIMESTAMP(step_inx)
#define STATISTICS_UPDATE_CODE_LOOP()
#endif

#ifdef STATISTICS_CODE_TIMESTAMP_ENABLE
void statistics_code_timestamp_init(void);
void statistics_code_loop_inc(void);
void statistics_code_timestamps_update(uint32 step_inx);
#endif

#endif /* __HSCG_FIRMWARE_CODE_STATISTIC_H__ */